#include "sky_box_drawer.h"

SkyBoxDrawer::SkyBoxDrawer(SkyBoxShaderProgram *shaderProgram
                           , SkyBox *skyBox)
    :VertexDrawer(shaderProgram), m_skyBox(skyBox) {

    m_vbo->allocate(skyBox->getVertexData(), skyBox->getVertexByteSize());

    m_program->setAttribute(m_program->getAttrPosition()
                            , m_skyBox->getComponentSize()
                            , m_skyBox->getStride()
                            , 0);
    m_program->enableAttribute(m_program->getAttrPosition());
}

void SkyBoxDrawer::draw() {
    m_vao->bind();
    m_program->bind();

    glUniformMatrix4fv(m_program->getUniformMatrix()
                       , 1
                       , false
                       , m_matrix.data());
    glDrawElements(GL_TRIANGLES
                   , m_skyBox->getVertexIndexSize()
                   , GL_UNSIGNED_BYTE
                   , m_skyBox->getVertexElements());

    m_program->release();
}
